<?php

namespace App\Service\Index;

use App\Constants\ErrorCode;
use App\Model\Moment;
use App\Model\Report;
use App\Service\BaseService;

/**
 * 举报
 */
class ReportService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $images = $this->request->input('images', '');
        if (!$images) return $this->setError(ErrorCode::PARAMETER_ERROR, '请上传举报的图片！');
        $reportedUserId = $this->request->input('report_user_id', 0);
        $momentId = $this->request->input('report_moment_id', 0);
        if ($momentId) {
            $moment = Moment::find($momentId);
            $reportedUserId = $moment ? $moment->user_id : 0;
        }
        $reason = $this->request->input('reason', '');
        $images = $images ? explode(',', $images) : [];
        $desc = $this->request->input('desc', '');
        $result = Report::addRecord(
            $userId,
            $reportedUserId,
            $momentId,
            $reason,
            $images,
            $desc
        );
        return ['result' => 1];
    }
}
